package com.ia.aistream.controller.operating;//package com.ia.aistream.controller.operating;

import com.ia.aistream.common.annotation.Log;
import com.ia.aistream.common.core.controller.BaseController;
import com.ia.aistream.common.core.domain.AjaxResult;
import com.ia.aistream.common.core.page.TableDataInfo;
import com.ia.aistream.common.enums.BusinessType;
import com.ia.aistream.common.enums.ResponeCodeMsgEnums;
import com.ia.aistream.common.utils.poi.ExcelUtil;
import com.ia.aistream.manager.dxfcomponent.conf.DrawConf;
import com.ia.aistream.model.dxfcomponent.entity.DxfDraw;
import com.ia.aistream.model.operating.entity.DocContentParagraph;
import com.ia.aistream.model.operating.entity.DocIndex;
import com.ia.aistream.service.operating.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * content_paragraphController
 *
 * @author aistream
 * @date 2021-01-20
 */
@Controller
@RequestMapping("/docContentPargraph/paragraphandtitle")
public class DocContentParagraphAndTitleController extends BaseController
{
    @Autowired
    private DrawConf drawConf;
    private String prefix = "doc/analysis";

    @Autowired
    private IDocContentPargraphAndTitleService docContentPargraphAndTitleService;
    @Autowired
    private IDocIndexService docIndexService;
    @Autowired
    private IDocDocumentService docDocumentService;

    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult addPargraphAndTitle(MultipartFile[] fileName) throws Exception {
        return toAjax(docContentPargraphAndTitleService.saveDocDateSource(fileName));
    }

    /**
     * 数据展示页
     * @return
     */
    @RequiresPermissions("docContentPargraph:paragraphandtitle:view")
    @GetMapping()
    public String component(ModelMap mmap)
    {
        mmap.addAttribute("httpUrl", drawConf.getHttpUrl());
        return prefix + "/draw";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DocIndex docIndex)
    {
//        startPage();
        List<DocIndex> dxfDrawList = docIndexService.selectDocIndexList(docIndex);
        if(dxfDrawList==null){
            dxfDrawList = new ArrayList<>();
        }

        return getDataTable(dxfDrawList);
    }

    @RequiresPermissions("docContentPargraph:paragraphandtitle:view")
    @GetMapping("/query")
    public String query()
    {
        return prefix + "/query";
    }


    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(long ids)
    {
        return toAjax(docDocumentService.removeDocDataService(ids));
    }

}
